package com.dianning.service.imp;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import org.apache.commons.logging.*;

import com.dianning.bean.Visitor;
import com.dianning.dao.VisitorDAO;
import com.dianning.exception.DianningException;
import com.dianning.service.VisitorService;

public class VisitorServiceImp implements VisitorService {

	private static final Log logger = LogFactory.getLog(VisitorServiceImp.class);

	private VisitorDAO visitorDAO;

	public VisitorDAO getVisitorDAO() {
		return visitorDAO;
	}

	public void setVisitorDAO(VisitorDAO visitorDAO) {
		this.visitorDAO = visitorDAO;
	}

	/**
	 * 保存Visitor对象
	 * 
	 * @param v
	 * 			Visitor对象
	 * @return Visitor
	 * 			Visitor对象
	 */
	public Visitor saveVisitor(Visitor v) throws DianningException {
		try {
			v = this.getVisitorDAO().saveVisitor(v);
			return v;
		} catch (Exception e) {
			logger.error(e);
			throw new DianningException(e);
		}
	}
	
	/**
	 * 更新Visitor对象
	 * 
	 * @param visitor
	 * 			Visitor对象
	 * @return Visitor
	 * 			Visitor对象
	 */
	public Visitor updateVisitor(Visitor v) throws DianningException{
		try {
			v = this.getVisitorDAO().updateVisitor(v);
			return v;
		} catch (Exception e) {
			logger.error(e);
			throw new DianningException(e);
		}
	}
	
	/**
	 * 根据主键ID获取Visitor对象
	 * 
	 * @param id
	 * 			主键ID
	 * @return Visitor
	 * 			Visitor对象
	 */
	public Visitor findVisitorById(long id){
		return this.getVisitorDAO().findVisitorById(id);
	}
	
	/**
	 * 要据IP uid 获取Visitor对象
	 * 
	 * @param ip
	 * 			String
	 * @param uid
	 * 			long
	 * @return Visitor
	 * 			Visitor对象
	 */
	public Visitor findVisitorByIpUid(String ip,long uid){
		return this.getVisitorDAO().findVisitorByIpUid(ip, uid);
	}
	
	/**
	 * 获取今天Visitor个数
	 * @return long
	 * 			Visitor个数
	 */
	public long getTodayVisitorNumByUid(long uid){
		return this.getVisitorDAO().getTodayVisitorNumByUid(uid);
	}
}
